unit GL_COA_DETAIL;


interface
uses
  Classes,SysUtils,DB,Uni,UniEngine;

type
  TGLCOADETAIL=class(TUniEngine)
  private
    FCOAID    : string;                   
    FCOADETAILID: string;
    FELECODE  : string;
    FDISPORDER: Extended;
    FLEVELNUM : Extended;
    FLASTVER  : string;
    FSETYEAR  : Extended;
    FISMUSTINPUT: Extended;
    FDEFAULTVALUE: string;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  published
    property COAID    : string read FCOAID     write FCOAID;
    property COADETAILID: string read FCOADETAILID write FCOADETAILID;
    property ELECODE  : string read FELECODE   write FELECODE;
    property DISPORDER: Extended read FDISPORDER write FDISPORDER;
    property LEVELNUM : Extended read FLEVELNUM  write FLEVELNUM;
    property LASTVER  : string read FLASTVER   write FLASTVER;
    property SETYEAR  : Extended read FSETYEAR   write FSETYEAR;
    property ISMUSTINPUT: Extended read FISMUSTINPUT write FISMUSTINPUT;
    property DEFAULTVALUE: string read FDEFAULTVALUE write FDEFAULTVALUE;    
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(AGLCOADETAIL:TGLCOADETAIL):TGLCOADETAIL;overload;        
    class procedure CopyIt(AGLCOADETAIL:TGLCOADETAIL;var Result:TGLCOADETAIL);overload;       
  end;

implementation

{ TGLCOADETAIL }
procedure TGLCOADETAIL.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('COA_ID').Value := COAID;
        ParamByName('COA_DETAIL_ID').Value := COADETAILID;
        ParamByName('ELE_CODE').Value := ELECODE;
        ParamByName('DISP_ORDER').Value := DISPORDER;
        ParamByName('LEVEL_NUM').Value := LEVELNUM;
        ParamByName('LAST_VER').Value := LASTVER;
        ParamByName('SET_YEAR').Value := SETYEAR;
        ParamByName('IS_MUSTINPUT').Value := ISMUSTINPUT;
        ParamByName('DEFAULT_VALUE').Value := DEFAULTVALUE; 
      end;
      otEdit:
      begin
        ParamByName('COA_ID').Value := COAID;
        ParamByName('COA_DETAIL_ID').Value := COADETAILID;
        ParamByName('ELE_CODE').Value := ELECODE;
        ParamByName('DISP_ORDER').Value := DISPORDER;
        ParamByName('LEVEL_NUM').Value := LEVELNUM;
        ParamByName('LAST_VER').Value := LASTVER;
        ParamByName('SET_YEAR').Value := SETYEAR;
        ParamByName('IS_MUSTINPUT').Value := ISMUSTINPUT;
        ParamByName('DEFAULT_VALUE').Value := DEFAULTVALUE; 
      end;  
      otDelt:
      begin
        ParamByName('COA_DETAIL_ID').Value := COADETAILID;
 
      end;  
    end;
  end;
end;

function TGLCOADETAIL.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('GL_COA_DETAIL',['COA_DETAIL_ID',COADETAILID],AUniConnection);
end;

function TGLCOADETAIL.GetNextIdex: Integer;
begin

end;

function TGLCOADETAIL.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin

end;

function TGLCOADETAIL.GetStrDelete: string;
begin
  Result:='DELETE FROM GL_COA_DETAIL WHERE   COA_DETAIL_ID=:COA_DETAIL_ID';
end;

function TGLCOADETAIL.GetStrInsert: string;
begin
  Result:='INSERT INTO GL_COA_DETAIL'
         +'    ( COA_ID, COA_DETAIL_ID, ELE_CODE, DISP_ORDER, LEVEL_NUM'
         +'    , LAST_VER, SET_YEAR, IS_MUSTINPUT, DEFAULT_VALUE)'
         +'    VALUES'
         +'    (:COA_ID,:COA_DETAIL_ID,:ELE_CODE,:DISP_ORDER,:LEVEL_NUM'
         +'    ,:LAST_VER,:SET_YEAR,:IS_MUSTINPUT,:DEFAULT_VALUE)';
end;

function TGLCOADETAIL.GetStrsIndex: string;
begin
  Result:=Format('%S',[COADETAILID]);
end;

function TGLCOADETAIL.GetStrUpdate: string;
begin
  Result:='UPDATE  GL_COA_DETAIL SET'
         +'    COA_ID=:COA_ID,'
         +'    ELE_CODE=:ELE_CODE,'
         +'    DISP_ORDER=:DISP_ORDER,'
         +'    LEVEL_NUM=:LEVEL_NUM,'
         +'    LAST_VER=:LAST_VER,'
         +'    SET_YEAR=:SET_YEAR,'
         +'    IS_MUSTINPUT=:IS_MUSTINPUT,'
         +'    DEFAULT_VALUE=:DEFAULT_VALUE'
         +'    WHERE COA_DETAIL_ID=:COA_DETAIL_ID';
end;

constructor TGLCOADETAIL.Create;
begin

end;

destructor TGLCOADETAIL.Destroy;
begin

  inherited;
end;

class function TGLCOADETAIL.ReadDS(AUniQuery: TUniQuery): TUniEngine;
var
  I:Integer;
  Field:TField;
  FieldName:string;
begin
  Result:=TGLCOADETAIL.Create;

  with TGLCOADETAIL(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      //if field.fieldname is not all uppercase,please use uppercase().
      FieldName:=Field.FieldName;
      if FieldName='COA_ID' then
      begin
        COAID    :=Field.AsString;
      end else
      if FieldName='COA_DETAIL_ID' then
      begin
        COADETAILID:=Field.AsString;
      end else
      if FieldName='ELE_CODE' then
      begin
        ELECODE  :=Field.AsString;
      end else
      if FieldName='DISP_ORDER' then
      begin
        DISPORDER:=Field.AsFloat;
      end else
      if FieldName='LEVEL_NUM' then
      begin
        LEVELNUM :=Field.AsFloat;
      end else
      if FieldName='LAST_VER' then
      begin
        LASTVER  :=Field.AsString;
      end else
      if FieldName='SET_YEAR' then
      begin
        SETYEAR  :=Field.AsFloat;
      end else
      if FieldName='IS_MUSTINPUT' then
      begin
        ISMUSTINPUT:=Field.AsFloat;
      end else
      if FieldName='DEFAULT_VALUE' then
      begin
        DEFAULTVALUE:=Field.AsString;
      end;
    end
  end;  
end;

class procedure TGLCOADETAIL.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
var
  I:Integer;
  Field:TField;
  FieldName:string;
begin
  if Result=nil then Exit;

  with TGLCOADETAIL(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      //if field.fieldname is not all uppercase,please use uppercase().
      FieldName:=Field.FieldName;
      if FieldName='COA_ID' then
      begin
        COAID    :=Field.AsString;
      end else
      if FieldName='COA_DETAIL_ID' then
      begin
        COADETAILID:=Field.AsString;
      end else
      if FieldName='ELE_CODE' then
      begin
        ELECODE  :=Field.AsString;
      end else
      if FieldName='DISP_ORDER' then
      begin
        DISPORDER:=Field.AsFloat;
      end else
      if FieldName='LEVEL_NUM' then
      begin
        LEVELNUM :=Field.AsFloat;
      end else
      if FieldName='LAST_VER' then
      begin
        LASTVER  :=Field.AsString;
      end else
      if FieldName='SET_YEAR' then
      begin
        SETYEAR  :=Field.AsFloat;
      end else
      if FieldName='IS_MUSTINPUT' then
      begin
        ISMUSTINPUT:=Field.AsFloat;
      end else
      if FieldName='DEFAULT_VALUE' then
      begin
        DEFAULTVALUE:=Field.AsString;
      end;
    end
  end;  
end;

class function  TGLCOADETAIL.CopyIt(AGLCOADETAIL: TGLCOADETAIL): TGLCOADETAIL;
begin
  Result:=TGLCOADETAIL.Create;
  TGLCOADETAIL.CopyIt(AGLCOADETAIL,Result)
end;

class procedure TGLCOADETAIL.CopyIt(AGLCOADETAIL:TGLCOADETAIL;var Result:TGLCOADETAIL);
begin
  if Result=nil then Exit;
  Result.COAID    :=AGLCOADETAIL.COAID;
  Result.COADETAILID:=AGLCOADETAIL.COADETAILID;
  Result.ELECODE  :=AGLCOADETAIL.ELECODE;
  Result.DISPORDER:=AGLCOADETAIL.DISPORDER;
  Result.LEVELNUM :=AGLCOADETAIL.LEVELNUM;
  Result.LASTVER  :=AGLCOADETAIL.LASTVER;
  Result.SETYEAR  :=AGLCOADETAIL.SETYEAR;
  Result.ISMUSTINPUT:=AGLCOADETAIL.ISMUSTINPUT;
  Result.DEFAULTVALUE:=AGLCOADETAIL.DEFAULTVALUE;
end;

end.

